load 'tutem_utils.rb'

def process_log_file(file_path)
  data_hash = {}

  prefix='combined.log:'
  idx = 0
  File.open(file_path, 'r').each do |line|
    line.chomp!
    next if !line.start_with?(prefix)
    data = line.split(prefix)[1];
    rec = JSON.parse(data)
    message = rec['message']
    time = rec['timestamp']
    if (message && time)
        match = message.match(/ruid# (\d+) \| tuid# (\d+)/)
        ruid = 0
        tuid = 0
        if match
            ruid = match[1].to_i
            tuid = match[2].to_i
        end
        if ruid>0 && tuid>0 && ruid!=tuid && ruid != 666
            data = {}
            data.store 'idx', idx
            data.store 'time', time
            data.store 'ruid', ruid
            data.store 'rinfo', userList[ruid]['name'].to_s + userList[ruid]['deparment'].to_s
            data.store 'tuid', tuid
            data.store 'tinfo', userList[tuid]['name'].to_s + userList[tuid]['deparment'].to_s
            data_hash.store idx, data
            idx += 1
        end
    end
  end
  data_hash
end

hash =  process_log_file 'mtx.log'
dump_hash_to_excel hash, 'mtx-839-refer', true
